#ifndef xpack_math_exp10r
#define xpack_math_exp10r
#pragma push_macro("xuser")
#undef  xuser
#define xuser mixc::math_exp10r::inc
#include"define/base_type.hpp"
#include"macro/xexport.hpp"
#include"meta/is_same.hpp"
#pragma pop_macro("xuser")

namespace mixc::math_exp10r{
    constexpr f64 f64_lut_1en0_1en15  [] = { 1e-0, 1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-6, 1e-7, 1e-8, 1e-9, 1e-10, 1e-11, 1e-12, 1e-13, 1e-14, 1e-15, };
    constexpr f64 f64_lut_1en16_1en240[] = { 1e-0, 1e-16, 1e-32, 1e-48, 1e-64, 1e-80, 1e-96, 1e-112, 1e-128, 1e-144, 1e-160, 1e-176, 1e-192, 1e-208, 1e-224, 1e-240,};
    constexpr f64 f64_lut_1en256      [] = { 1e0, 1e-256 };

    constexpr f32 f32_lut_1en0_1en38  [] = {
        1e-00f, 1e-01f, 1e-02f, 1e-03f, 1e-04f, 1e-05f, 1e-06f, 1e-07f, 1e-08f, 1e-09f,
        1e-10f, 1e-11f, 1e-12f, 1e-13f, 1e-14f, 1e-15f, 1e-16f, 1e-17f, 1e-18f, 1e-19f,
        1e-20f, 1e-21f, 1e-22f, 1e-23f, 1e-24f, 1e-25f, 1e-26f, 1e-27f, 1e-28f, 1e-29f,
        1e-30f, 1e-31f, 1e-32f, 1e-33f, 1e-34f, 1e-35f, 1e-36f, 1e-37f, 1e-38f,
    };
}

namespace mixc::math_exp10r::origin{
    template<class f64_t>
    requires(inc::is_same<f64_t, f64>)
    inline f64 exp10r_unsafe(uxx x){
        union {
            struct{
                uxx low : 4;
                uxx mid : 4;
                uxx hig : 1;
            };
            uxx full;
        }w;

        w.full    = x;
        return f64_lut_1en0_1en15[w.low] * f64_lut_1en16_1en240[w.mid] * f64_lut_1en256[w.hig];
    }

    template<class f64_t>
    requires(inc::is_same<f64_t, f64>)
    inline f64 exp10r(uxx x){
        if (x > 307){
            return 0;
        }
        return exp10r_unsafe<f64>(x);
    }

    template<class f32_t>
    requires(inc::is_same<f32_t, f32>)
    inline f32 exp10r_unsafe(uxx x){
        return f32_lut_1en0_1en38[x];
    }

    template<class f32_t>
    requires(inc::is_same<f32_t, f32>)
    inline f32 exp10r(uxx x){
        if (x > 38){
            return 0;
        }
        return exp10r_unsafe<f32>(x);
    }
}

#endif

xexport_space(mixc::math_exp10r::origin)